 function FIGURE_GENERATE(rep,ww,rollover_subset,size_subset,labor,one_step,controls,chol,...
     bcdz,jq,cmr,mpt,time_fe,near_var,nonlin,ni,ser,cogs,markup,ind,fe)
%  clear
%  rep=20;
% fe=0;
% ww=0;%WW excercise
% rollover_subset=0;%large short term debt firms subset
% size_subset=0;%small firms subset
% labor=0;%Labor excercise by firm size
% one_step=0;%Include all VAR lagged variables as controls and have EBP act as the credit supply shock
% controls=0;%adding lagged leverage and sales growth in regressions;
% chol=0;%shock from different cholesky ordering 
% bcdz=0;%BCDZ SHOCK
% jq=0;%JQ SHOCK
% cmr=0;%CMR SHOCK
% mpt=0;%MPT SHOCK
% time_fe=0;%industry time fixed effects: put [U,S,V] = svds(A,length(A)) in line 18 of pinv;
% near_var=0;%NEAR-VARs INSEAD OF LPs
% nonlin=0;%do sign-dependent estimation
% ni=0;%ni specification
% ser=0;%remove service industries
% cogs=0;%value added framework
% markup=0;%accounting for markups
% ind=0;%accounting for output-capital price heterogeneity
% %FOR MANUAL UNCOMMENT UP TO HERE
% % or=21,22,23 are monthly fbp, ip, and unemp
% month=0;%if it's 1 you produce monthly figures; only put 1 for just_fig=1;
% %only do it for or=21,22,23
 siz=0;%if 1 we add cubed shock term
sav=1;%save results
just_fig=0;%1 if no estimation
fig=1;%if 1 do fig on top of estimation
fi=0;%if 1 take financial excess bond premium
annual=0;%if it's 1 we do CTOT
oecd=1;%if oecd==0 do EA_US ANALYSIS; oecd=1 is rr analysis
quart=0;
ham=0;
hp=0;
in=1;%inital obs
ed=0;%41 end in 2007q4
%     in=1;
%    ed=1;%41 end in 2007q4
 r=[];%which countries to remove
% r=[3,9,15,16,20,30,22,27,34,11,18,2,10,14,25,29,36,37,38,23,24];%EMBI
state=0;%if it's 1 then do state-dependent figure


if oecd==1
s=11;title1{1}='Percentage Deviation';title2=repmat(title1,1,rep);
%      title2{12}='Financial Distress Units'; 
     title2{35}='Basis Points';          title2{21}='Basis Point Deviation';     
title2{23}='Percentage Point Deviation';title2{5}='Percentage Point Deviation';
title2{26}='Percentage Point Deviation';title2{27}='Percentage Point Deviation';
title2{28}='Percentage Point Deviation';title2{40}='Percentage Point Deviation';

     title2{38}='Basis Points';
     title3{1}='Percentage Point Deviation';title4=repmat(title3,1,rep);
 title4{21}='Basis Point Deviation';
     w=repmat(100,rep,1);w(12)=100;w(23)=1;
    
else
rep=23; x=1:60;

s=11;title1{1}='Percentage Points';title2=repmat(title1,1,rep);
%      title2{12}='Financial Distress Units'; 
     title2{1}='Basis Points';     
     title2{2}='Basis Points';title2{5}='Basis Points';     
     title2{6}='Basis Points';
w=repmat(100,rep,1);w1=repmat(100*1.00,rep,1);

% w(12)=1;
end

%        for i=[2:5,7,26:28,40,56,41,42,43,45,17,18,30,31,55]%BASELINE QUARTERLY
   i=1;%BASELINE MONTHLY
          if just_fig==0     
%       for i=[1:5,7,8,17,18,26:28,30,31,40,41,42,43,45,55,56,58,35,39];
%   for i=[1:5,7,17,18,26:28,40,41,42,43,45,55,56,58,35,39];  
[m_lin(:,:,i),qu_lin(:,:,:,i),mis_lin(:,:,i),qu_mis(:,:,:,i),m_low(:,:,i),...
    qu_low(:,:,:,i),m_up(:,:,i),qu_up(:,:,:,i),...
    m_asym(:,:,:,i),qu_asym(:,:,:,i),m_low_size(:,:,i),...
    qu_low_size(:,:,:,i),m_up_size(:,:,i),qu_up_size(:,:,:,i),...
    m_asym_size(:,:,i),qu_asym_size(:,:,:,i),m_low_cap(:,:,i),...
    qu_low_cap(:,:,:,i),m_up_cap(:,:,i),qu_up_cap(:,:,:,i),...
    m_asym_cap(:,:,i),qu_asym_cap(:,:,:,i),m_low_all(:,:,i),...
    qu_low_all(:,:,:,i),m_up_all(:,:,i),qu_up_all(:,:,:,i),...
    m_asym_all(:,:,i),qu_asym_all(:,:,:,i),~,...
    m_lin1(:,:,i),qu_lin1(:,:,:,i),mis_lin1(:,:,i),qu_mis1(:,:,:,i),m_low1(:,:,i),...
    qu_low1(:,:,:,i),m_up1(:,:,i),qu_up1(:,:,:,i),...
    m_asym1(:,:,:,i),qu_asym1(:,:,:,i),m_low_size1(:,:,i),...
    qu_low_size1(:,:,:,i),m_up_size1(:,:,i),qu_up_size1(:,:,:,i),...
    m_asym_size1(:,:,i),qu_asym_size1(:,:,:,i),m_low_cap1(:,:,i),...
    qu_low_cap1(:,:,:,i),m_up_cap1(:,:,i),qu_up_cap1(:,:,:,i),...
    m_asym_cap1(:,:,i),qu_asym_cap1(:,:,:,i),m_low_all1(:,:,i),...
    qu_low_all1(:,:,:,i),m_up_all1(:,:,i),qu_up_all1(:,:,:,i),...
    m_asym_all1(:,:,i),qu_asym_all1(:,:,:,i),...
    m_lin2(:,:,i),qu_lin2(:,:,:,i),mis_lin2(:,:,i),qu_mis2(:,:,:,i),m_low2(:,:,i),...
    qu_low2(:,:,:,i),m_up2(:,:,i),qu_up2(:,:,:,i),...
    m_asym2(:,:,:,i),qu_asym2(:,:,:,i),m_low_size2(:,:,i),...
    qu_low_size2(:,:,:,i),m_up_size2(:,:,i),qu_up_size2(:,:,:,i),...
    m_asym_size2(:,:,i),qu_asym_size2(:,:,:,i),m_low_cap2(:,:,i),...
    qu_low_cap2(:,:,:,i),m_up_cap2(:,:,i),qu_up_cap2(:,:,:,i),...
    m_asym_cap2(:,:,i),qu_asym_cap2(:,:,:,i),m_low_all2(:,:,i),...
    qu_low_all2(:,:,:,i),m_up_all2(:,:,i),qu_up_all2(:,:,:,i),...
    m_asym_all2(:,:,i),qu_asym_all2(:,:,:,i)]=BAYES_MEDIAN_QU(i,oecd,annual,ed,in,r,quart,ham,hp,fi,siz,ni,ser,cogs,markup,ind,nonlin,near_var,time_fe,...
    chol,bcdz,jq,cmr,mpt,controls,one_step,labor,size_subset,rollover_subset,ww,rep,fe);
          else
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
             chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
             rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS.mat;
              end
           if ni==1&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_NI.mat;
           end
           if ni==0&&ser==1&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_SER.mat;
           end 
              if ni==0&&ser==0&&cogs==1&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_COGS.mat;
              end 
             if ni==0&&ser==0&&cogs==0&&markup==1&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_MARKUP.mat;
             end 
             if ni==0&&ser==0&&cogs==0&&markup==0&&ind==1&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_IND.mat;
             end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==1&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_NONLIN.mat;
              end  
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==1&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_NEAR_VAR.mat;
              end  
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==1&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_TIME_FE.mat;
              end 
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==1&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_CHOL.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==1&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_BCDZ.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==1&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_JQ.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==1&&mpt==0&&controls==0&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_CMR.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==1&&controls==0&&one_step==0&&...
                      labor==0&&rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_MPT.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==1&&one_step==0&&labor==0&&...
                      rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_CONTROLS.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==1&&...
                      labor==0&&rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_ONE_STEP.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&...
                      labor==1&&rollover_subset==0&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_LABOR.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&...
                      labor==0&&rollover_subset==1&&size_subset==0&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_ROLLOVER_SUBSET.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&...
                      labor==0&&rollover_subset==0&&size_subset==1&&ww==0&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_SIZE_SUBSET.mat;
              end
              if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&...
                      labor==0&&rollover_subset==0&&size_subset==0&&ww==1&&fe==0
                       load          BASELINE_QUARTERLY_RESULTS_WW.mat;
              end
              if fe==1
                                      load          BASELINE_QUARTERLY_RESULTS_FE.mat;
              end
          end
     %NON-STATE-DEPENDENT MODEL
     if labor==0
if fig==1
    if any(i==21:23)
        x=1:60;
    else
        x=1:20;
    end
     if one_step==1
w=repmat(100*0.266092437991343,rep,1);%NORMALIZE TO ONE STD SHOCK

     end
if ww==0
            subplot(2,3,1),plot(x,w(i)*m_lin(:,1:size(x,2),i),'b-',x,w(i)*qu_lin(:,1:size(x,2),1,i),'b--',x,w(i)*qu_lin(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Median Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,5),plot(x,w(i)*mis_lin(:,1:size(x,2),i),'b-',x,w(i)*qu_mis(:,1:size(x,2),1,i),'b--',x,w(i)*qu_mis(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Capital-Misallocation-Induced TFP Response','fontsize',s);xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,2),plot(x,w(i)*m_up_all(:,1:size(x,2),i),'b-',x,w(i)*qu_up_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,3),plot(x,w(i)*m_low_all(:,1:size(x,2),i),'b-',x,w(i)*qu_low_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,4),plot(x,w(i)*m_asym_all(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Weight Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
set(gcf,'position',get(0,'screensize'))   
% size1 = get(gcf,'Position');
% size1 = size1(3:4); % the last two elements are width and height of the figure
% set(gcf,'PaperUnit','points'); % unit for the property PaperSize
% set(gcf,'PaperSize',size1);
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL%d.pdf',i),'-transparent');
end
if ni==1&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
       chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_NI%d.pdf',i),'-transparent');
end
if ni==0&&ser==1&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_SER%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==1&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_COGS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==1&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
set(gcf,'position',get(0,'screensize'))   
export_fig(sprintf('BZ_FIRM_ALL_MARKUP%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==1&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_IND%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==1&&near_var==0&&time_fe==0&&fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_NONLIN_POS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==1&&time_fe==0&&fe==0&&...
                      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_NEAR_VAR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==1&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_TIME_FE%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
       chol==1&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_CHOL%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
     chol==0&&bcdz==1&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_BCDZ%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==1&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_JQ%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==1&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_CMR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==1&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_MPT%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==1&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_CONTROLS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==1&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_ONE_STEP%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==1&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_LABOR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==1&&size_subset==0
export_fig(sprintf('BZ_FIRM_ALL_ROLLOVER_SUBSET%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==1
export_fig(sprintf('BZ_FIRM_ALL_SIZE_SUBSET%d.pdf',i),'-transparent');
end
if fe==1
 export_fig(sprintf('BZ_FIRM_ALL_FE%d.pdf',i),'-transparent');
   
end
if size(m_asym,2)>1
    m_asym=m_asym';
end
subplot(3,3,1),plot(x,w(i)*m_up(:,1:size(x,2),i),'b-',x,w(i)*qu_up(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High MPK Firm Response','fontsize',s,'Color',[0,0,0.005]); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,2),plot(x,w(i)*m_low(:,1:size(x,2),i),'b-',x,w(i)*qu_low(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low MPK Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,3),plot(x,w(i)*m_asym(1:size(x,2),i),'b-',x,w(i)*qu_asym(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low MPK Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,4),plot(x,w(i)*m_up_size(:,1:size(x,2),i),'b-',x,w(i)*qu_up_size(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_size(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,5),plot(x,w(i)*m_low_size(:,1:size(x,2),i),'b-',x,w(i)*qu_low_size(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_size(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,6),plot(x,w(i)*m_asym_size(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_size(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_size(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Size Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,7),plot(x,w(i)*m_up_cap(:,1:size(x,2),i),'b-',x,w(i)*qu_up_cap(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_cap(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,8),plot(x,w(i)*m_low_cap(:,1:size(x,2),i),'b-',x,w(i)*qu_low_cap(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_cap(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,9),plot(x,w(i)*m_asym_cap(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_cap(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_cap(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low Capital Share Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])

set(gcf,'position',get(0,'screensize')) 
% size1 = get(gcf,'Position');
% size1 = size1(3:4); % the last two elements are width and height of the figure
% set(gcf,'PaperUnit','points'); % unit for the property PaperSize
% set(gcf,'PaperSize',size1);
% set(gcf,'position',get(0,'screensize'))   
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST%d.pdf',i),'-transparent');

end
if ni==1&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_NI%d.pdf',i),'-transparent');
end
if ni==0&&ser==1&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_SER%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==1&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_COGS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==1&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_MARKUP%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==1&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_IND%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==1&&near_var==0&&time_fe==0&&fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_NONLIN_POS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==1&&time_fe==0&&fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_NEAR_VAR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==1&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_TIME_FE%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
 chol==1&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_CHOL%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==1&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_BCDZ%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==0&&jq==1&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_JQ%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==0&&jq==0&&cmr==1&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_CMR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
   chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==1&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_MPT%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==1&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_CONTROLS%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
  chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==1&&labor==0&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_ONE_STEP%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
 chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==1&&rollover_subset==0&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_LABOR%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
 chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==1&&size_subset==0
export_fig(sprintf('BZ_FIRM_DIST_ROLLOVER_SUBSET%d.pdf',i),'-transparent');
end
if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&fe==0&&...
 chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==1
export_fig(sprintf('BZ_FIRM_DIST_SIZE_SUBSET%d.pdf',i),'-transparent');
end
if fe==1
export_fig(sprintf('BZ_FIRM_DIST_FE%d.pdf',i),'-transparent');
end
close all


if nonlin==1
              subplot(2,3,1),plot(x,w(i)*m_lin1(:,1:size(x,2),i),'b-',x,w(i)*qu_lin1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_lin1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Median Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,5),plot(x,w(i)*mis_lin1(:,1:size(x,2),i),'b-',x,w(i)*qu_mis1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_mis1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Capital-Misallocation-Induced TFP Response','fontsize',s);xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,2),plot(x,w(i)*m_up_all1(:,1:size(x,2),i),'b-',x,w(i)*qu_up_all1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_all1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,3),plot(x,w(i)*m_low_all1(:,1:size(x,2),i),'b-',x,w(i)*qu_low_all1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_all1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,4),plot(x,w(i)*m_asym_all1(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_all1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_all1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Weight Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
set(gcf,'position',get(0,'screensize'))   

export_fig(sprintf('BZ_FIRM_ALL_NONLIN_NEG%d.pdf',i),'-transparent');

if size(m_asym,2)>1
    m_asym1=m_asym1';
end
subplot(3,3,1),plot(x,w(i)*m_up1(:,1:size(x,2),i),'b-',x,w(i)*qu_up1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High MPK Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,2),plot(x,w(i)*m_low1(:,1:size(x,2),i),'b-',x,w(i)*qu_low1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low MPK Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,3),plot(x,w(i)*m_asym1(1:size(x,2),i),'b-',x,w(i)*qu_asym1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low MPK Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,4),plot(x,w(i)*m_up_size1(:,1:size(x,2),i),'b-',x,w(i)*qu_up_size1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_size1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,5),plot(x,w(i)*m_low_size1(:,1:size(x,2),i),'b-',x,w(i)*qu_low_size1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_size1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,6),plot(x,w(i)*m_asym_size1(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_size1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_size1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Size Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,7),plot(x,w(i)*m_up_cap1(:,1:size(x,2),i),'b-',x,w(i)*qu_up_cap1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_cap1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,8),plot(x,w(i)*m_low_cap1(:,1:size(x,2),i),'b-',x,w(i)*qu_low_cap1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_cap1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,9),plot(x,w(i)*m_asym_cap1(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_cap1(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_cap1(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low Capital Share Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])

set(gcf,'position',get(0,'screensize'))   

export_fig(sprintf('BZ_FIRM_DIST_NONLIN_NEG%d.pdf',i),'-transparent');
close all
              subplot(2,3,1),plot(x,w(i)*m_lin2(:,1:size(x,2),i),'b-',x,w(i)*qu_lin2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_lin2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Median Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,5),plot(x,w(i)*mis_lin2(:,1:size(x,2),i),'b-',x,w(i)*qu_mis2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_mis2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Capital-Misallocation-Induced TFP Response','fontsize',s);xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,2),plot(x,w(i)*m_up_all2(:,1:size(x,2),i),'b-',x,w(i)*qu_up_all2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_all2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,3),plot(x,w(i)*m_low_all2(:,1:size(x,2),i),'b-',x,w(i)*qu_low_all2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_all2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Weight Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,4),plot(x,w(i)*m_asym_all2(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_all2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_all2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Weight Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
set(gcf,'position',get(0,'screensize'))   

export_fig(sprintf('BZ_FIRM_ALL_NONLIN_ASYM%d.pdf',i),'-transparent');
close all
if size(m_asym,2)>1
    m_asym2=m_asym2';
end
subplot(3,3,1),plot(x,w(i)*m_up2(:,1:size(x,2),i),'b-',x,w(i)*qu_up2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High MPK Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,2),plot(x,w(i)*m_low2(:,1:size(x,2),i),'b-',x,w(i)*qu_low2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low MPK Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,3),plot(x,w(i)*m_asym2(1:size(x,2),i),'b-',x,w(i)*qu_asym2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low MPK Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,4),plot(x,w(i)*m_up_size2(:,1:size(x,2),i),'b-',x,w(i)*qu_up_size2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_size2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,5),plot(x,w(i)*m_low_size2(:,1:size(x,2),i),'b-',x,w(i)*qu_low_size2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_size2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Small Size Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,6),plot(x,w(i)*m_asym_size2(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_size2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_size2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Large Vs. Small Size Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,7),plot(x,w(i)*m_up_cap2(:,1:size(x,2),i),'b-',x,w(i)*qu_up_cap2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_cap2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(3,3,8),plot(x,w(i)*m_low_cap2(:,1:size(x,2),i),'b-',x,w(i)*qu_low_cap2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_cap2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low Capital Share Firm Response','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(3,3,9),plot(x,w(i)*m_asym_cap2(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_cap2(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_cap2(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low Capital Share Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])

set(gcf,'position',get(0,'screensize'))   
export_fig(sprintf('BZ_FIRM_DIST_NONLIN_ASYM%d.pdf',i),'-transparent');
end
close all
else
           subplot(2,3,1),plot(x,w(i)*m_lin(:,1:size(x,2),i),'b-',x,w(i)*qu_lin(:,1:size(x,2),1,i),'b--',x,w(i)*qu_lin(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Median Firm Response','fontsize',s,'Color', [0,0,0.005]); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,5),plot(x,w(i)*mis_lin(:,1:size(x,2),i),'b-',x,w(i)*qu_mis(:,1:size(x,2),1,i),'b--',x,w(i)*qu_mis(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Capital-Misallocation-Induced TFP Response','fontsize',s);xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,2),plot(x,w(i)*m_up_all(:,1:size(x,2),i),'b-',x,w(i)*qu_up_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_up_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High WW Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
            subplot(2,3,3),plot(x,w(i)*m_low_all(:,1:size(x,2),i),'b-',x,w(i)*qu_low_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_low_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('Low WW Firm Response','fontsize',s); xlabel('Horizon');ylabel(title2{i},'fontsize',s);xlim([0 size(x,2)])
           subplot(2,3,4),plot(x,w(i)*m_asym_all(:,1:size(x,2),i),'b-',x,w(i)*qu_asym_all(:,1:size(x,2),1,i),'b--',x,w(i)*qu_asym_all(:,1:size(x,2),2,i),'b--','LineWidth',3);
title('High Vs. Low WW Response Difference','fontsize',s); xlabel('Horizon');ylabel(title4{i},'fontsize',s);xlim([0 size(x,2)])
set(gcf,'position',get(0,'screensize'))   

export_fig(sprintf('BZ_FIRM_ALL_WW%d.pdf',i),'-transparent');
end




end
if sav==1&&length(x)==20
    if ww==0

    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS');
    end
    if ni==1&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_NI');
    end
    if ni==0&&ser==1&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_SER');
    end
    if ni==0&&ser==0&&cogs==1&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
        chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_COGS');
    end
   if ni==0&&ser==0&&cogs==0&&markup==1&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_MARKUP');
   end 
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==1&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_IND');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==1&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_NONLIN');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==1&&time_fe==0&&...
   chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_NEAR_VAR');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==1&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_TIME_FE');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
    chol==1&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_CHOL');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==1&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_BCDZ');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
    chol==0&&bcdz==0&&jq==1&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_JQ');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==1&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_CMR');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==1&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_MPT');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
     chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==1&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_CONTROLS');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
    chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==1&&labor==0&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_ONE_STEP');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==1&&rollover_subset==0&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_LABOR');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==1&&size_subset==0
    save('BASELINE_QUARTERLY_RESULTS_ROLLOVER_SUBSET');
    end
    if ni==0&&ser==0&&cogs==0&&markup==0&&ind==0&&nonlin==0&&near_var==0&&time_fe==0&&...
      chol==0&&bcdz==0&&jq==0&&cmr==0&&mpt==0&&controls==0&&one_step==0&&labor==0&&rollover_subset==0&&size_subset==1
    save('BASELINE_QUARTERLY_RESULTS_SIZE_SUBSET');
    end
    if fe==1
        save('BASELINE_QUARTERLY_RESULTS_FE');
    end
else
      save('BASELINE_QUARTERLY_RESULTS_WW');
  
end
    end
   if sav==1&&length(x)==60
    save('BASELINE_MONTHLY_RESULTS');
   end
     end
% if sav==1
%      save('BASELINE_RESULTS');
%  end